Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Spree::Payment offsets #5008

Merged

Conversation

waiting-for-dev
Copy link
Contributor

@waiting-for-dev waiting-for-dev commented Apr 11, 2023

Summary

The old system for refunds was removed in 2014.

We deprecate the .offset_payment scope, which is in turn used by the .offsets association. We inline its usage on a couple of methods until we perform the full removal.

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@waiting-for-dev waiting-for-dev requested a review from a team as a code owner April 11, 2023 14:11
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Apr 11, 2023
@waiting-for-dev waiting-for-dev self-assigned this Apr 11, 2023
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of questions to better understand if we have alternatives. Thanks!

core/app/models/spree/payment.rb Outdated Show resolved Hide resolved
core/app/models/spree/payment.rb Outdated Show resolved Hide resolved
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/remove_offsets branch from 66b3652 to 83f1dc6 Compare April 12, 2023 10:10
@waiting-for-dev waiting-for-dev changed the title Deprecate Spree::Payment#offsets Deprecate Spree::Payment offsets Apr 12, 2023
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/remove_offsets branch from 83f1dc6 to 32f5fae Compare April 12, 2023 10:14
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left another small note for our future selves, but I'm also ok as is.

@@ -101,7 +111,10 @@ def offsets_total
# @return [BigDecimal] the amount of this payment minus the offsets
# (old-style refunds) and refunds
def credit_allowed
amount - (offsets_total.abs + refunds.sum(:amount))
amount - (
(self.class.where("source_type = 'Spree::Payment' AND amount < 0 AND state = 'completed' AND source_id = ?", id).sum(:amount)).abs +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, maybe a variable makes sense? We could add a comment to easily recall which part of the method we need to remove when offset_payment will be gone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that I needed to repeat the inline on Spree::Order#has_non_reimbursement_related_refunds?, and that the code should really be very short-lived (we should remove it in #4989), I'd prefer to keep it simple if you think it's ok 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same suggestion as alberto, but also fine with this give its expected short life

The old system for refunds was removed in 2014 [1].

We deprecate the `.offset_payment` scope, which is in turn used by the
`.offsets` association. We inline its usage on a couple of methods until
we perform the full removal.

[1] - spree/spree#4883
@waiting-for-dev waiting-for-dev force-pushed the waiting-for-dev/remove_offsets branch from 32f5fae to 03ae9a2 Compare April 12, 2023 14:46
Copy link
Contributor

@rainerdema rainerdema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@@ -101,7 +111,10 @@ def offsets_total
# @return [BigDecimal] the amount of this payment minus the offsets
# (old-style refunds) and refunds
def credit_allowed
amount - (offsets_total.abs + refunds.sum(:amount))
amount - (
(self.class.where("source_type = 'Spree::Payment' AND amount < 0 AND state = 'completed' AND source_id = ?", id).sum(:amount)).abs +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same suggestion as alberto, but also fine with this give its expected short life

@waiting-for-dev waiting-for-dev merged commit fd277b0 into solidusio:master Apr 13, 2023
@waiting-for-dev waiting-for-dev deleted the waiting-for-dev/remove_offsets branch April 13, 2023 12:30
kennyadsl added a commit to nebulab/solidus that referenced this pull request Apr 14, 2023
This was a leftover for a feature that has been removed long time ago.
Please use Refunds now.

Ref solidusio#5008
kennyadsl added a commit to nebulab/solidus that referenced this pull request Apr 18, 2023
This was a leftover for a feature that has been removed long time ago.
Please use Refunds now.

Ref solidusio#5008
kennyadsl added a commit to nebulab/solidus that referenced this pull request Apr 18, 2023
This was a leftover for a feature that has been removed long time ago.
Please use Refunds now.

Ref solidusio#5008
kennyadsl added a commit to nebulab/solidus that referenced this pull request Apr 19, 2023
This was a leftover for a feature that has been removed long time ago.
Please use Refunds now.

Ref solidusio#5008
kennyadsl added a commit to nebulab/solidus that referenced this pull request Apr 24, 2023
This was a leftover for a feature that has been removed long time ago.
Please use Refunds now.

Ref solidusio#5008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants